package com.huluobo.a2107jetpackkotlindemo.room

import android.accounts.Account
import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Update

/**
 *  Created by LC on 2023/11/24.
 *  Dao Data Access Object 数据转换为对象
 *  用于数据库中的数据转换为bean
 */
@Dao
interface AccountDao {
    /**
     * 插入数据
     * onConflict = OnConflictStrategy.REPLACE 插入是的规则,如果出现重复插入,则替换
     */
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun insertAccount(accountBean: AccountBean)

    /**
     * 查询账号列表
     */
    @Query("select * from Account")
    fun queryAccountList(): List<AccountBean>?

    /**
     * 根据登录账号查询表中是否存在这个账号
     */
    @Query("select * from Account where _loginAccount ==:loginAccount")
    fun findAccountByLoginAccount(loginAccount: String): AccountBean?

    @Update
    fun updateAccountBean(accountBean: AccountBean)

    @Delete
    fun deleteAccountBean(accountBean: AccountBean)
}
